package hn.sigit.model.hnd.ladmshadow;

import hn.sigit.model.commons.IResponsibility;
import hn.sigit.model.ladm.administrative.LA_ResponsibilityType;

import java.io.Serializable;
import javax.persistence.*;
@Entity
@org.hibernate.annotations.Proxy(lazy=false)
@Table(name="Responsibility", schema="ladmshadow")
@Inheritance(strategy=InheritanceType.JOINED)
@DiscriminatorValue("Responsibility")
@PrimaryKeyJoinColumn(name="RRRID", referencedColumnName="ID")
public class Responsibility extends RRR implements Serializable, Cloneable, IResponsibility {
	private static final long serialVersionUID = 1L;
	
	private LA_ResponsibilityType type;
	
	protected Responsibility() {
	}

	public static Responsibility newResponsibility(long ladmId, long presentationId, boolean isReadOnly, boolean isSnapshot) {
		Responsibility responsibility = new Responsibility();
		
		responsibility.setLadmId(ladmId);
		responsibility.setPresentationId(presentationId);
		responsibility.setReadOnly(isReadOnly);
		responsibility.setSnapshot(isSnapshot);
		
		return responsibility;
	}
	
	@Column(name="Type", nullable=true)
	@Enumerated(EnumType.STRING)
	public LA_ResponsibilityType getType() {
		return type;
	}
	public void setType(Enum<?> value) {
		this.type = (LA_ResponsibilityType) value;
	}
	
	
	@Override
	public Responsibility clone() {
		Responsibility clonedResponsibility = (Responsibility) super.clone();
		
		clonedResponsibility.setType(type);
		
		return clonedResponsibility;
	}
	
	@Transient
	@Override
	public int responsibilitiesHash() {
		return (int)((long)getShare().hashCode() + getExtPID() + getType().hashCode());
	}

	@Transient
	@Override
	public long getExtPID() {
		return getParty().getExtParty().getExtPID();
	}

}
